import 'package:hive/hive.dart';

part 'share.g.dart';

@HiveType(typeId: 1)
class ShareEntity extends HiveObject {
  @HiveField(0)
  final String id;

  @HiveField(1)
  final String description;

  @HiveField(2)
  final String image;

  @HiveField(3)
  final String emotion;

  @HiveField(4)
  final String date;

  @HiveField(5)
  final List<String> commentIds;

  @HiveField(6)
  final int browses;

  @HiveField(7)
  final String video;

  ShareEntity({
    required this.id,
    required this.description,
    required this.image,
    required this.emotion,
    required this.date,
    required this.commentIds,
    required this.browses,
    this.video = '',
  });

  factory ShareEntity.fromJson(Map<String, dynamic> json) {
    return ShareEntity(
      id: json['id'] as String,
      description: json['description'] as String,
      image: json['image'] as String,
      emotion: json['emotion'] as String,
      date: json['date'] as String,
      commentIds: (json['commentIds'] as List<dynamic>).cast<String>(),
      browses: json['browses'] as int,
      video: json['video'] as String? ?? '',
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'description': description,
      'image': image,
      'emotion': emotion,
      'date': date,
      'commentIds': commentIds,
      'browses': browses,
      'video': video,
    };
  }

  ShareEntity copyWith({
    String? id,
    String? description,
    String? image,
    String? emotion,
    String? date,
    List<String>? commentIds,
    int? browses,
    String? video,
  }) {
    return ShareEntity(
      id: id ?? this.id,
      description: description ?? this.description,
      image: image ?? this.image,
      emotion: emotion ?? this.emotion,
      date: date ?? this.date,
      commentIds: commentIds ?? this.commentIds,
      browses: browses ?? this.browses,
      video: video ?? this.video,
    );
  }

  @override
  String toString() {
    return 'ShareEntity(id: $id, description: $description, image: $image, emotion: $emotion, date: $date, commentIds: $commentIds, browses: $browses, video: $video)';
  }

  bool get hasVideo => video.isNotEmpty;

  bool get hasImage => image.isNotEmpty;
}

final List<ShareEntity> sampleShares = [
  ShareEntity(
    id: '1',
    description:
        'Sometimes, the little things mean the most. Today I\'m thankful for a sunny morning, a good cup of coffee, and a kind smile from a stranger.',
    image: 'assets/image/post1.png',
    emotion: 'happy',
    date: '2025-08-01 08:15:32',
    commentIds: ['c1', 'c2'],
    browses: 45,
    video:
        'assets/video/1.mp4',
  ),
  ShareEntity(
    id: '2',
    description:
        'It\'s like I\'m walking in circles, unsure of which path to take. Has anyone else felt like this before? How do you find clarity in moments like this?',
    image: 'assets/image/post2.png',
    emotion: 'disappointed',
    date: '2025-08-01 19:42:18',
    commentIds: ['c3', 'c4'],
    browses: 32,
  ),
  ShareEntity(
    id: '3',
    description:
        'Today, I sat by the window and watched the rain. Sometimes, it\'s the quiet moments that make you feel most alive.',
    image: 'assets/image/post3.png',
    emotion: 'love',
    date: '2025-08-01 14:28:45',
    commentIds: ['c5', 'c6'],
    browses: 28,
    video: '',
  ),
  ShareEntity(
    id: '4',
    description:
        'I feel overwhelmed because I keep saying yes to things I don\'t have time for. Does anyone have advice on setting boundaries without feeling guilty?',
    image: 'assets/image/post4.png',
    emotion: 'disappointed',
    date: '2025-08-01 11:33:27',
    commentIds: ['c7', 'c8'],
    browses: 67,
  ),
  ShareEntity(
    id: '5',
    description:
        'After weeks of hard work, I finally accomplished my goal today! Just wanted to share some positivity and remind everyone that small wins matter.',
    image: 'assets/image/post5.png',
    emotion: 'happy',
    date: '2025-08-01 16:55:12',
    commentIds: ['c9', 'c10', 'c11'],
    browses: 89,
    video: '',
  ),
  ShareEntity(
    id: '6',
    description:
        'I made a mistake at work and it keeps replaying in my head. How do you stop the negative thoughts from taking over?',
    image: 'assets/image/post6.png',
    emotion: 'disappointed',
    date: '2025-07-31 09:17:53',
    commentIds: ['c12', 'c13'],
    browses: 41,
  ),
  ShareEntity(
    id: '7',
    description:
        'Today I took a break from everything and went for a walk in the park. Sometimes, you just need a little time for yourself to recharge.',
    image: 'assets/image/post7.png',
    emotion: 'love',
    date: '2025-07-31 15:22:08',
    commentIds: ['c14', 'c15'],
    browses: 56,
  ),
  ShareEntity(
    id: '8',
    description:
        'It\'s like no matter what I do, things just don\'t seem to work out right now. How do you keep going when progress feels so slow?',
    image: 'assets/image/post8.png',
    emotion: 'bored',
    date: '2025-07-31 20:44:31',
    commentIds: ['c16', 'c17'],
    browses: 73,
  ),
  ShareEntity(
    id: '9',
    description:
        'Today, someone complimented me on something I worked hard on, and it made my day. Just wanted to remind everyone that kind words can go a long way!',
    image: 'assets/image/post9.png',
    emotion: 'happy',
    date: '2025-07-31 12:38:47',
    commentIds: ['c18', 'c19', 'c20'],
    browses: 92,
  ),
  ShareEntity(
    id: '10',
    description:
        'Things are tough right now, but I\'m learning to celebrate each small step forward. Progress might be slow, but it\'s still progress.',
    image: 'assets/image/post10.png',
    emotion: 'love',
    date: '2025-08-01 18:05:29',
    commentIds: ['c21', 'c22', 'c23'],
    browses: 64,
  ),
];

List<ShareEntity> getAllShares() {
  return sampleShares;
}
